﻿namespace Yom.WebService.Default
{
    using System;
    using System.Collections.Generic;
    using System.Web;
    using Yom.Common;
    using Yom.Template;

    public class DefaultSearch : BasePage
    {
        public string OutWrite()
        {
            string Key = Factory.Request("Key").UrlDeCode();
            string P = Factory.Request("P");
            int page = (string.IsNullOrEmpty(P) ? 1 : P.ToInt());

            SetCommon();
            SetTopList();
            SetRecommList();
            SkinTheme.SetLabel("PageTitle", "漫画搜索 -- " + Key);
            SkinTheme.SetLabel("ListName", "搜索结果");
            List<Yom.Model.Comic> list = new Yom.Data.Comic().GetList(20, page, "[ComicName] like '%" + Key + "%'", true);
            SkinTheme.SetBlock("List", list.Count);
            int num = 0;
            foreach (Yom.Model.Comic comic in list)
            {
                SkinTheme.SetLabel(string.Format("List.CID_{0}", num), comic.ComicID.ToString());
                SkinTheme.SetLabel(string.Format("List.SaveName_{0}", num), new Yom.Data.Category().GetModel(comic.CategoryID).SaveName);
                SkinTheme.SetLabel(string.Format("List.TID_{0}", num), Math.Ceiling(Convert.ToDouble(comic.ComicID) / 1000).ToString());
                SkinTheme.SetLabel(string.Format("List.FaceExt_{0}", num), comic.FaceExt);
                SkinTheme.SetLabel(string.Format("List.Name_{0}", num), comic.ComicName);
                SkinTheme.SetLabel(string.Format("List.Visit_{0}", num), comic.Visit.ToString());
                SkinTheme.SetLabel(string.Format("List.LastName_{0}", num), (string.IsNullOrEmpty(new Yom.Data.Volume().GetLastVolume(comic.ComicID).VolumeName) ? "暂无更新" : new Yom.Data.Volume().GetLastVolume(comic.ComicID).VolumeName));
                SkinTheme.SetLabel(string.Format("List.State_{0}", num), new Yom.Data.Comic().GetState(comic.State));
                SkinTheme.SetLabel(string.Format("List.LastTime_{0}", num), comic.LastTime.ToString("yyyy-mm-dd"));
                num++;
            }
            string Multi = Factory.GetPager(20, page, new Yom.Data.Comic().GetCount("[ComicName] like '%" + Key + "%'"), "Search_" + Key + "_<{Page}>.ashx");
            SkinTheme.SetLabel("MultiPage", Multi.Replace("_1.ashx", ".ashx"));

            return SkinTheme.RunParse("List.html");
        }
    }
}